#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>

int main() {
    int num;
    std::cin >> num;
    if (num % 1 > 0 || num < 1000 || num > 9999) {
        std::cout << "0" << std::endl;
        return 0;
    }

    std::string num_str = std::to_string(num);
    std::vector<int> slices = {
        std::stoi(num_str.substr(0, 2)),
        std::stoi(num_str.substr(1, 2)),
        std::stoi(num_str.substr(2, 2)),
        std::stoi(num_str.substr(0, 3)),
        std::stoi(num_str.substr(1, 3)),
        std::stoi(num_str)
    };

    int answer = 0;
    for (int slice : slices) {
        bool prime = true;
        for (int div = 2; div <= std::sqrt(slice); ++div) {
            if (slice % div == 0) {
                prime = false;
                break;
            }
        }
        if (prime) {
            answer = std::max(answer, slice);
        }
    }

    std::cout << answer << std::endl;
    return 0;
}


